package com.zhkj.txg.module.mine.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.utils.SpanUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.mine.entity.RefundListEntity
import com.zhkj.txg.utils.ImageUtils

class AfterSaleAdapter : BaseQuickAdapter<RefundListEntity, BaseViewHolder>(R.layout.item_after_sale), LoadMoreModule {

    init {
        addChildClickViewIds(R.id.tvAfterSaleShopName, R.id.ivAfterSaleProduct, R.id.ivAfterSaleShop)
    }

    override fun convert(helper: BaseViewHolder, item: RefundListEntity) {
        helper.setText(R.id.tvAfterSaleShopName, item.shop?.shopName ?: context.getString(R.string.sell_owner))
            .setText(R.id.tvAfterSaleType, item.typeText)
            .setText(R.id.tvAfterSaleProductName, item.goods?.goodsName)
            .setText(R.id.tvAfterSaleProductSpec, item.goods?.specValue)
            .setText(R.id.tvAfterSaleRefundAmount, SpanUtil.setPrefixMoneyStr("退款:", item.refundMoney))
            .setText(R.id.tvAfterSaleStatus, getStatusText(item.status))
            .setTextColorRes(
                R.id.tvAfterSaleStatus,
                if (item.status == 4 || item.status == 5) R.color.colorGradientMain else R.color.colorDefaultText
            )
        ImageUtils.loadCircleImage(context, helper.getView(R.id.ivAfterSaleShop), item.shop?.shopImg ?: "")
        ImageUtils.loadRoundCornerImage(context, helper.getView(R.id.ivAfterSaleProduct), item.goods?.image ?: "")
    }

    private fun getStatusText(status: Int) = context.getString(
        when (status) {
            -2 -> R.string.refund_cancel
            -1 -> R.string.refund_deny
            1 -> R.string.refund_grand
            2 -> R.string.refund_back
            3 -> R.string.refund_receive
            4 -> R.string.refund_change_finish
            5 -> R.string.refund_refund_finish
            else -> R.string.refund_waiting
        }
    )
}